---
layout: example
categories: example/v1.0.0
version: v1.0.0
title: Click event in a popup
description: Create a click event in a marker popup with Mapbox.js and jQuery.
tags:
  - ui
  - markers
---
<div id='map'></div>

<!-- jQuery is required for this example. -->
<script src='https://code.jquery.com/jquery-1.11.0.min.js'></script>
<script>
var map = L.mapbox.map('map')
    .setView([43.6475, -79.3838], 14)
    .addLayer(L.mapbox.styleLayer('mapbox://styles/mapbox/streets-v11'));

var marker = L.marker([43.6475, -79.3838], {
      icon: L.mapbox.marker.icon({
        'marker-color': '#9c89cc'
      })
    })
    .bindPopup('<button class="trigger">Say hi</button>')
    .addTo(map);

// The HTML we put in bindPopup doesn't exist yet, so we can't just say
// $('#mybutton'). Instead, we listen for click events on the map element which
// will bubble up from the tooltip, once it's created and someone clicks on it.
$('#map').on('click', '.trigger', function() {
    alert('Hello from Toronto!');
});
</script>
